jQuery(document).ready(function($) {

    $("[placeholder]").placeholder();

    $('#post_event_button').live("click", function(e){
        postEvent();
    });

    $('.remove_participant').live("click", function(e){
        remove_participant($(this).attr('id'));
       /* var participant_block = $(this).closest('.participant');

        participant_block.fadeOut(500, function(){
            $(this).remove();
        });*/
    });

    $('.add_participant').live("click", function(e){
        add_participant($(this).attr('id'));

    });
    $('.up_weight').live("click", function(e){
        up_weight($(this).attr('id'));

    });


    //POST POLL
   function postEvent(){

       var postData = $('#event_form').serialize();
       $.ajax({
          url: base_url + "post/post_event",
          type: "POST",
          data: postData,
          success: function(data){
               var post = $(data);
               post.insertBefore(".item:eq(0)");
               post.hide().slideDown();
               resetPollForm();
          }
        });
   }

    //remove event participant
   function remove_participant(event_id){
       //var postData = {event_id: event_id};
       
       $.ajax({
          url: base_url + "event/remove_participant/"+event_id,
          type: "GET",
          success: function(data){
              $('.events').html(data);
          }
        });
   }

    //add event participant
   function add_participant(event_id){

       $.ajax({
          url: base_url + "event/add_participant/"+event_id,
          type: "GET",
          success: function(data){
              $('.events').html(data);
          }
        });
   }

    //up weight participant
   function up_weight(event_id){

       $.ajax({
          url: base_url + "event/up_weight/"+event_id,
          type: "GET",
          success: function(data){
              $('.events').html(data);
          }
        });
   }
});